package com.example.mygame.controller;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.mygame.service.Myadopter;
import com.example.mygame.R;
import com.example.mygame.pojo.User;
import com.example.mygame.service.SqliteUtils;

import java.util.List;

public class SpeedLogin extends AppCompatActivity {

    private SqliteUtils sqliteUtils;

    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_speed_login);

        listView = findViewById(R.id.list);

        sqliteUtils = new SqliteUtils(this);

        List<User> userList = sqliteUtils.queryAllFromDb();

        ListView listView = (ListView) findViewById(R.id.list);

        listView.setAdapter(new Myadopter(userList,this));

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView name = view.findViewById(R.id.name);
                TextView password = view.findViewById(R.id.password);
                String Fname = name.getText().toString();
                String Fpassword = password.getText().toString();

                Intent intent = new Intent(SpeedLogin.this, Login.class);

                Bundle bundle = new Bundle();
                bundle.putString("userName",Fname);
                bundle.putString("password",Fpassword);

                intent.putExtras(bundle);

                startActivity(intent);

            }
        });




    }

}